// pages/user/user.js
// var dingdan = require("/dingdan.js");
var app = getApp()
Page( {
  data: {
    userInfo: {},
    orderInfo:{},
    projectSource: 'https://github.com/liuxuanqiang/wechat-weapp-mall',
    userListInfo:'',
    rzinfo:'normal',
     orderList0: [],
    orderList1: [],
    orderList2: [],
    orderList3: [],
    orderList4: [],
    pay_num:0,
    Has_num:0,
    rec_num:0,
    finish_num:0,
    refund_num:0,
  },
  onLoad: function () {
      var that = this
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function(userInfo){
        //更新数据
        that.setData({
          userInfo:userInfo,
          loadingHidden: true
        })
      });  
      that.loadOrderStatus();
      for(let i=1;i<=4;i++){
        let statue=i+'0';
        // console.log('status')
        // console.log(statue)
        that.loadOrderList(statue)
      }
  },
  onShow:function(){
    var that=this;
    that.loadOrderStatus();
    // wx.request({
    //   url: app.d.ceshiUrl + '/Api/Renzheng/checkrz',
    //   method: 'post',
    //   data: {
    //     uid: app.globalData.userInfo.id
    //   },
    //   header: {
    //     'Content-Type': 'application/x-www-form-urlencoded'
    //   },
    //   success: function (res) {
    //     //--init data        
    //     var status = res.data.status;
    //     if (status == 1) {
    //       that.setData({
    //         rzinfo: res.data.respondData
    //       });
    //       that.loadShopOrder();
    //     } 
    //   },
    //   error: function (e) {
    //     wx.showToast({
    //       title: '网络异常！',
    //       duration: 30000
    //     });
    //   }
    // });
  },
  loadShopOrder:function (e){
    var that=this;
    wx.request({
      url: app.d.ceshiUrl + '/Api/User/getShopOrderNum',
      method: "post",
      data: {
        uid:app.globalData.userInfo.id
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
          if(res.data.status==1){
            that.setData({
              shopOrder: res.data.err
            })
          }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },
  loadOrderList: function (status) {
    console.log(status)
    var that = this;
    wx.request({
      url: app.d.ceshiUrl + '/transaction/OrderFormMgrAction!listByOrderStatus',
      method: 'get',
      data: {
        order_status: status,
      },
      header: app.globalData.header,
      success: function (res) {
        //--init data   
        console.log('loadOrderList')
        console.log(that.data.isStatus)
        console.log(that.data.currentTab);
        console.log(res)
        var status = res.data.status;
        // var status = res.data.statusCode;
        var list = res.data.rows;

         

        switch (status) {
          case 10:
            
            console.log(" case 0:")

            that.setData({
              orderList0: list,
              pay_num: rows.length,
              winHeight: 900,
            });
            break;
          case 20:
            console.log(" case 1:")
            that.setData({
              orderList1: list,
              has_num: rows.length,
              winHeight: 900,
            });
            break;
          case 30:
            console.log(" case 2:")
            that.setData({
              orderList2: list,
              rec_num: rows.length,
              winHeight: 900,
            });
            break;
          case 40:
            that.setData({
              orderList3: list,
              finish_num: rows.length,
              winHeight: 900,
            });
            break;
        }
      },
      fail: function () {
        // fail
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      }
    });
  },
  loadOrderStatus:function(){
    //获取用户订单数据
    var that = this;
    console.log(app.d.userId);
    console.log(app.globalData.userInfo);
    // wx.request({
    //   url: app.d.ceshiUrl + '/Api/User/getorder',
    //   method:'post',
    //   data: {
    //     userId: app.globalData.userInfo.id,
    //   },
    //   header: {
    //     'Content-Type':  'application/x-www-form-urlencoded'
    //   },
    //   success: function (res) {
    //     //--init data        
    //     var status = res.data.status;
    //     if(status==1){
    //       that.setData({
    //         orderInfo:res.data.orderInfo,
    //         shop_status:res.data.shop_status
    //       });
    //     }else{
    //       wx.showToast({
    //         title: res.data.err,
    //         duration: 2000
    //       });
    //     }
    //   },
    //   error:function(e){
    //     wx.showToast({
    //       title: '网络异常！',
    //       duration: 30000
    //     });
    //   }
    // });
  },

})